home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
TransSkel.cpt
/
MSkelHelp.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-01-07
|
7KB
|
259 lines
{ TransSkel multiple-window demonstration: Help module}
{ This module handles a help window, in which text may be scrolled but}
{ not edited. A TextEdit record is used to hold the text, though.}
{ 14 June 1986 Paul DuBois}
{ 7 January 1987 Ported to LightSpeed Pascal by Owen Hartnett }
{ Ωhm Software Company }
UNIT MSkelHelp;
INTERFACE
USES
MultiSkelGlobs, common, TransSkelpas;
PROCEDURE HelpWindInit;
IMPLEMENTATION
VAR
teHelp : TEHandle; { handle to help window TextEdit record }
helpScroll : ControlHandle; { help window scroll bar }
helpLine, halfPage : integer; { line currently at top of window }
{ number of lines in half a window }
PROCEDURE Halt;
BEGIN
TEDispose(teHelp);
DisposeControl(helpScroll);
CloseWindow(helpWind);
END;
{ Scroll to the correct position. lDelta is the}
{ amount to CHANGE the current scroll setting by.}
PROCEDURE DoScroll (lDelta : integer);
VAR
newLine : integer;
BEGIN
newLine := helpLine + lDelta;
IF newLine < 0 THEN
newLine := 0;
IF newline > GetCtlMax(helpScroll) THEN
newline := GetCtlMax(helpScroll);
SetCtlValue(helpScroll, newLine);
lDelta := (helpLine - newLine) * (teHelp^^.lineHeight);
TEScroll(0, lDelta, teHelp);
helpLine := newLine;
END;
{ Filter proc for tracking mousedown in scroll bar. The part code}
{ of the part originally hit is stored as the control's reference}
{ value.}
PROCEDURE TrackScroll (theScroll : ControlHandle;
partCode : integer);
VAR
lDelta : integer;
BEGIN
IF (partCode = GetCRefCon(theScroll)) THEN
BEGIN
CASE partCode OF
inUpButton :
lDelta := -1;
inDownButton :
lDelta := 1;
inPageUp :
lDelta := -halfPage;
inPageDown :
lDelta := halfPage;
OTHERWISE
;
END;
DoScroll(lDelta);
END;
END;
{ Handle hits in scroll bar}
PROCEDURE Mouse (thePt : Point;
t : longint;
mods : integer);
VAR
thePart, ignore : integer;
BEGIN
thePart := TestControl(helpScroll, thePt);
IF thePart = inThumb THEN
BEGIN
ignore := TrackControl(helpScroll, thePt, NIL);
DoScroll(GetCtlValue(helpScroll) - helpline);
END
ELSE IF thePart <> 0 THEN
BEGIN
SetCRefCon(helpScroll, longint(thePart));
ignore := TrackControl(helpScroll, thePt, @TrackScroll);
END;
END;
{ Update help window. The update event might be in response to a}
{ window resizing. If so, resize the rects and recalc the linestarts}
{ of the text. To resize the rects, only the right edge of the}
{ destRect need be changed (the bottom is not used, and the left and}
{ top should not be changed). The viewRect should be sized to the}
{ screen. Pull text down if necessary to fill window.}
PROCEDURE update (resized : Boolean);
VAR
r : Rect;
visLines, lHeight, topLines, nLines, scrollLines, ignore : integer;
BEGIN
r := helpWind^.portRect;
EraseRect(r);
IF resized THEN
BEGIN
r.left := r.left + 4;
r.bottom := r.bottom - 2;
r.top := r.top + 2;
r.right := r.right - 19;
teHelp^^.destRect.right := r.right;
teHelp^^.viewRect := r;
TECalText(teHelp);
lHeight := teHelp^^.lineHeight;
nLines := teHelp^^.nLines;
visLines := (r.bottom - r.top) DIV lHeight;
halfPage := visLines DIV 2;
topLines := (r.top - teHelp^^.destRect.top) DIV lHeight;
scrollLines := visLines - (nLines - topLines);
IF (scrollLines > 0) AND (topLines > 0) THEN
BEGIN
IF scrollLines > topLines THEN
scrollLInes := topLines;
TEScroll(0, scrollLines * lHeight, teHelp);
END;
scrollLines := nLines - visLines;
helpLine := (r.top - teHelp^^.destRect.top) DIV lHeight;
{ move and resize the scroll bar as well. The ValidRect call is done}
{ because the HideControl adds the control bounds box to the update}
{ region - which would generate another update event! Since everything}
{ gets redrawn below, the ValidRect is used to cancel the update.}
HideControl(helpScroll);
r := helpWind^.portRect;
r.left := r.right - 15;
r.bottom := r.bottom - 14;
r.top := r.top - 1;
r.right := r.right + 1;
SizeControl(helpScroll, r.right - r.left, r.bottom - r.top);
MoveControl(helpScroll, r.left, r.top);
IF nLines - visLines < 0 THEN
ignore := 0
ELSE
ignore := nLines - vislines;
SetCtlMax(helpScroll, ignore);
SetCtlValue(helpScroll, helpLine);
ShowControl(helpScroll);
END;
DrawGrowBox(helpWind);
DrawControls(helpWind); { redraw scroll bar }
r := teHelp^^.viewRect;
TEUpdate(r, teHelp); { redraw text display }
ValidRect(helpWind^.portRect);
END;
{ When the window comes active, disable the Edit menu and highlight}
{ the scroll bar if there are any lines not visible in the content}
{ region. When the window is deactivated, enable the Edit menu and}
{ un-highlight the scroll bar.}
PROCEDURE Activate (active : Boolean);
VAR
ignore : integer;
BEGIN
DrawGrowBox(helpWind);
IF active THEN
BEGIN
DisableItem(editMenu, 0);
IF GetCtlMax(helpScroll) > 0 THEN
ignore := 0
ELSE
ignore := 255;
HiLiteControl(helpScroll, ignore);
END
ELSE
BEGIN
EnableItem(editMenu, 0);
HiLiteControl(helpScroll, 255);
END;
DrawMenuBar;
END;
PROCEDURE HelpWindInit;
VAR
r : Rect;
textHandle : Handle;
visLines, scrollLines : integer;
BEGIN
helpWind := GetNewWindow(helpWindRes, NIL, WindowPtr(-1));
SkelWindow(helpWind, @Mouse, NIL, @Update, @Activate, NIL, @Halt, NIL, true);
TextFont(0);
TextSize(0);
r := helpWind^.portRect;
r.left := r.left + 4;
r.bottom := r.bottom - 2;
r.top := r.top + 2;
r.right := r.right - 19;
teHelp := TENew(r, r);
textHandle := GetResource('TEXT', helpTextRes); {read help text}
HLock(textHandle);
TEInsert(textHandle^, GetHandleSize(textHandle), teHelp);
HUnlock(textHandle);
ReleaseResource(textHandle); { done with it, so goodbye }
{ Now figure out how many lines will fit in the window and how many}
{ will not. Determine the number of lines in half a window for use}
{ in tracking clicks in the page up and page down regions of the}
{ scroll bar. Then create the scroll bar . Make sure the borders }
{ overlap the window frame and the frame of the grow box. }
visLines := (r.bottom - r.top) DIV teHelp^^.lineHeight;
scrollLines := teHelp^^.nLines - visLines;
halfPage := visLines DIV 2;
helpline := 0;
r := helpWind^.portRect;
r.left := r.right - 15;
r.bottom := r.bottom - 14;
r.top := r.top - 1;
r.right := r.right + 1;
{ Build the scroll bar. Don't need to bother testing whether to}
{ highlight it or not, since that will be done in response to the}
{ activate event.}
helpScroll := NewControl(helpWind, r, '', true, helpLine, 0, scrollLines, scrollBarProc, 0);
{ GetNewWindow generates an update event for entire portRect.}
{ Cancel it, since the everything has been drawn already,}
{ except for the grow box (which will be drawn in response}
{ to the activate event).}
ValidRect(helpWind^.portRect);
END;
END.